const Router = require('koa-router');
const router = new Router();
const tool = require('../../tools/tool')
const {db, QueryTypes} = require("../../models/db");

router.post('/deliver/getHist', async ctx => {
    let tenantId = ctx.user.tenantId;
    let body = ctx.request.body;
    let beginDate = body.beginDate;
    let endDate = body.endDate;
    let searchTxt = body.searchTxt;
    let sql = `select id,billNo,billDate,ctime,deliverNames,driverName,licence from  cargo where tenantId=${tenantId} `

    if (searchTxt) {
        sql += ` and searchTxt like '%${searchTxt}%' `
    } else {
        if (beginDate) {
            sql += ` and billDate >= '${beginDate}' `
        }
        if (endDate) {
            sql += ` and billDate <= '${endDate}' `
        }
    }

    sql += ' order by billDate desc '
    let list = await db.query(sql, {type: QueryTypes.SELECT})
    return ctx.suc('', list );
})


module.exports = router;
